package com.liang.lesson2;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestInsert {
    public static void main(String[] args) {
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            conn = JdbcUntils.getConnection();  // 获取数据库连接
            st = conn.createStatement();

            // 假设 id 字段是自增的，删除 id 字段的插入
            String sql = "INSERT INTO users(id,`NAME`,`PASSWORD`,`email`,`birthday`)" +
                    " VALUES(12,'liang','123456','24736743@qq.com','2020-01-01')";
            int i = st.executeUpdate(sql);

            if (i > 0) {
                System.out.println("插入成功！！！");
            } else {
                System.out.println("插入失败！！！");
            }
        } catch (SQLException e) {
            System.out.println("SQL Error: " + e.getMessage());
            e.printStackTrace();
        } finally {
            JdbcUntils.release(conn, st, rs);
        }
    }
}